import { server } from "@/utils/http";
//1. 查询品牌列表
//请求参数类型限制
export interface reqTrademarkParamsType {
  page: number;
  limit: number;
}
//返回值类型限制
export interface reqTrademarkReturnItemType extends reqAddTradeParamsType {
  id: number;
}
export type reqTrademarkReturnRecordsType = reqTrademarkReturnItemType[];
export interface reqTrademarkReturnType {
  records: reqTrademarkReturnRecordsType;
  total: number;
  size: number;
  current: number;
  searchCount: boolean;
  pages: number;
}
export const requestTrademarkList = ({
  page,
  limit,
}: reqTrademarkParamsType) => {
  return server.get<any, reqTrademarkReturnType>(
    `/admin/product/baseTrademark/${page}/${limit}`
  );
};

//2. 修改品牌

export const requestUpdateTrademark = (
  trademark: reqTrademarkReturnItemType
) => {
  return server.put<any, null>(
    `/admin/product/baseTrademark/update`,
    trademark
  );
};

//3. 删除品牌

export const requestDeleteTrademark = (id: number) => {
  return server.delete<any, null>(`/admin/product/baseTrademark/remove/${id}`);
};

//4. 新增品牌
export interface reqAddTradeParamsType {
  tmName: string;
  logoUrl: string;
}
export const requestAddTrademark = (trademark: reqAddTradeParamsType) => {
  return server.post<any, null>(
    `/admin/product/baseTrademark/save`,
    trademark
  );
};

//获取所有的品牌列表
export interface TmListType {
  id: number;
  tmName: string;
  logoUrl: string;
}
export const requestAllTmList = () => {
  return server.get<any, TmListType[]>(
    `/admin/product/baseTrademark/getTrademarkList`
  );
};

/*  下面是attr
   -----------------------------------------------------------------------------------
  -----------------------------------------------------------------------------------
  -----------------------------------------------------------------------------------
  -----------------------------------------------------------------------------------
*/


/* 
  以下是三级分类的内容

*/
export interface reqCategoryItemType {
  id: number;
  name: string;
  category1Id?: number;
  category2Id?: number;
}

export type reqCategoryType = reqCategoryItemType[];

//1.请求一级分类列表
export const requestCategory1 = () => {
  return server.get<any, reqCategoryType>(`/admin/product/getCategory1`);
};

//2.请求二级分类列表
export const requestCategory2 = (category1Id: number) => {
  return server.get<any, reqCategoryType>(
    `/admin/product/getCategory2/${category1Id}`
  );
};

//3.请求三级分类列表
export const requestCategory3 = (category2Id: number) => {
  return server.get<any, reqCategoryType>(
    `/admin/product/getCategory3/${category2Id}`
  );
};

/* 
  以下是Attr的内容
*/

//某个属性内属性值列表的类型
export interface attrValueListType {
  isShow?: boolean;
  id?: number;
  valueName: string;
  attrId: number | undefined;
  isEdit?: boolean;
}

//某个属性的类型
export interface attrListItemType {
  id?: number;
  attrName: string;
  categoryId: number;
  categoryLevel: number;
  attrValueList: attrValueListType[];
  attrIdValueId?:string
}
//属性列表的类型
export type attrListType = attrListItemType[];

//4.获取当前三级分类的属性列表
export const requestAttrList = (
  category1Id: number,
  category2Id: number,
  category3Id: number
) => {
  return server.get<any, attrListType>(
    `/admin/product/attrInfoList/${category1Id}/${category2Id}/${category3Id}`
  );
};

//5.删除某个属性
export const requestDeleteAttr = (attrId: number) => {
  return server.delete<any, null>(`/admin/product/deleteAttr/${attrId}`);
};

//6.新增或修改属性
export const requestUpdateOrAddAttr = (newAttr: attrListItemType) => {
  return server.post<any, null>(`/admin/product/saveAttrInfo`, newAttr);
};

